#!/bin/bash

# file name
#name=$(basename -- "$0")
#name="${name%.*}"

# param name
name=$@

# enter name
#read -p "Enter keystore name：" name

directory="../config"
if [ ! -d "$directory" ]; then
    mkdir -p "$directory"
fi

# 30 years
keytool -genkeypair -keyalg RSA -keysize 2048 -validity 10950 \
    -dname "CN=$name,OU=$name,O=$name" \
    -keystore $directory/$name.jks \
    -storepass $name \
    -alias $name \
    -keypass $name \
    || exit 0
cat <<EOF > $directory/key.properties
storeFile=$directory/$name.jks
storePassword=$name
keyAlias=$name
keyPassword=$name
EOF
